<template>
  <div class="advance-table-body">
    <!--搜索栏-->
    <el-form class="search-form--inset" ref="elForm" :model="queryParams" inline size="small" label-width="100px" label-position="left">
      <el-form-item label="发布状态">
        <el-select v-model="queryParams.status">
          <el-option label="已发布" value="0"></el-option>
          <el-option label="未发布" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="公告标题">
        <el-input v-model="queryParams.title" placeholder="请输入" :style="{width: '100%'}"></el-input>
      </el-form-item>
      <trust-query-filter-operation :searchAdvanced.sync="searchAdvanced" @query="searchAction" @reset="resetAction"></trust-query-filter-operation>
    </el-form>
    <!--操作栏-->
    <div class="table-operator">
      <el-button type="primary" size="small" plain @click="clickBtnAdd">发布新公告</el-button>
    </div>
    <!--表格-->
    <el-table
      class="k-table"
      ref="table"
      @selection-change="handleSelectionChange"
      :data="tableList"
      v-loading="loading"
    >
      <el-table-column label="公告标题" align="left" prop="title" min-width="100px" show-overflow-tooltip />
      <el-table-column label="公告内容" align="left" prop="content" min-width="100px" show-overflow-tooltip />
      <el-table-column label="创建时间" align="left" prop="createTime" min-width="80" show-overflow-tooltip />
      <el-table-column label="发布状态" align="left" prop="status" :formatter="fStatus" show-overflow-tooltip min-width="100"/>
      <el-table-column label="操作" align="left" width="150" fixed="right">
        <template #default="{ row }">
          <el-button type="text" v-if="row.status==1" @click="clickBtnPublic(row)">发布</el-button>
          <el-button type="text" v-if="row.status==1" @click="clickBtnEdit(row)">编辑</el-button>
          <el-button type="text" style="color: orangered" @click="clickBtnDel(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <trust-pagination
      :total="total"
      :page-size.sync="queryParams.pageSize"
      :current-page.sync="queryParams.pageNum"
      @size-change="handleSizeChange" @current-change="handleCurrentChange"></trust-pagination>
    <notice-issued-dialog ref="noticeIssuedDialogRef"></notice-issued-dialog>
  </div>
</template>
<script>
import { saTableMixin } from '@/views/custom/mixin/saTableMixin';
import NoticeIssuedDialog from '@/views/custom/systemAnnouncement/noticeIssued/noticeIssuedDialog.vue';
import request from '@/utils/request';
export default {
  name: "noticeIssued",//公告发布
  components: { NoticeIssuedDialog },
  mixins: [saTableMixin],
  data() {
    return {
      rules: [],
      options: [],
    }
  },
  mounted() {
    this.requestData("/notice_info/list","get",this.queryParams);
  },
  methods:{
    clickBtnPublic(row){
      this.$confirm('是否确认发布公告?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.requestDataPublic(row);
      })
    },
    clickBtnAdd(){
      this.$refs.noticeIssuedDialogRef.openDiaolog(0,null,()=>{
        this.refreshTableData();
      });
    },
    clickBtnEdit(row){
      this.$refs.noticeIssuedDialogRef.openDiaolog(1,row.id,()=>{
        this.refreshTableData();
      });
    },
    clickBtnDel(row){
      this.$confirm('删除后公告无法恢复，用户端将不在显示本公告内容，是否确认删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.requestDataDel(row.id);
      })
    },
    //网络-发布
    requestDataPublic(row){
      let status = (row.status==="0")?"1":"0";
      request({
        url:`/notice_info`,
        method:'put',
        data: {id:row.id,status:status},
      }).then(response =>{
        this.$message.success(response.msg);
        this.refreshTableData();
      })
    },
    //网络-删除
    requestDataDel(id){
      request({
        url:`/notice_info/${id}`,
        method:'delete',
        data: {},
      }).then(response =>{
        this.$message.success(response.msg);
        this.refreshTableData();
      })
    },
    fStatus(row, column, cellValue, index){
      if (cellValue === "0"){
        return "已发布";
      }else {
        return "未发布"
      }
    },
  }
}
</script>
